package cn.org.seventh.web.common;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class EncoderWraper extends HttpServletRequestWrapper {

	public EncoderWraper(HttpServletRequest request) {
		super(request);
	}

	public String getParameter(String arg0) {
		String str = super.getParameter(arg0);
		if (null == str) {
			return null;
		} else {
			String encode = null;
			try {
				encode = new String(str.getBytes("ISO-8859-1"), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				return super.getParameter(arg0);
			}
			return encode;
		}
	}

	public String[] getParameterValues(String arg0) {
		String[] str = super.getParameterValues(arg0);
		if (null != str) {
			String[] encode = new String[str.length];
			try {
				for (int i = 0; i < str.length; i++) {
					encode[i] = new String(str[i].getBytes("ISO-8859-1"),
							"UTF-8");
				}
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				return super.getParameterValues(arg0);
			}
			return encode;
		}
		return super.getParameterValues(arg0);
	}

}
